package com.example.service.impl;

import com.example.domain.CultureProduct;
import com.example.mapper.CultureProductDao;
import com.example.service.CultureProductService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CultureProduct)表服务实现类
 *
 * @author makejava
 * @since 2025-03-29 17:57:44
 */
@Service("cultureProductService")
public class CultureProductServiceImpl implements CultureProductService {
    @Resource
    private CultureProductDao cultureProductDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CultureProduct queryById(Integer id) {
        return this.cultureProductDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param cultureProduct 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @Override
    public Page<CultureProduct> queryByPage(CultureProduct cultureProduct, PageRequest pageRequest) {
        long total = this.cultureProductDao.count(cultureProduct);
        return new PageImpl<>(this.cultureProductDao.queryAllByLimit(cultureProduct, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param cultureProduct 实例对象
     * @return 实例对象
     */
    @Override
    public CultureProduct insert(CultureProduct cultureProduct) {
        this.cultureProductDao.insert(cultureProduct);
        return cultureProduct;
    }

    /**
     * 修改数据
     *
     * @param cultureProduct 实例对象
     * @return 实例对象
     */
    @Override
    public CultureProduct update(CultureProduct cultureProduct) {
        this.cultureProductDao.update(cultureProduct);
        return this.queryById(cultureProduct.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.cultureProductDao.deleteById(id) > 0;
    }

    @Override
    public List<CultureProduct> queryProductByShop(Integer id) {
        return this.cultureProductDao.queryProductByShop(id);
    }
}
